package com.yuanfeng.job.job;


import com.yuanfeng.commoms.dto.goods.AppSeckillGoodsVO;
import com.yuanfeng.job.mapper.SeckillGoodsMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

//限时秒杀库存为零时下架商品
public class UpdateSeckillNumStartJob implements BaseJob {
    private static final Logger logger = LoggerFactory.getLogger(UpdateActivityGoodsStatus.class);

    @Autowired
    private SeckillGoodsMapper seckillGoodsMapper;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //限时秒杀
        List<AppSeckillGoodsVO> seckillGoodsResults = seckillGoodsMapper.selectSeckillNum();
        if (seckillGoodsResults != null && seckillGoodsResults.size()>0){
            for (AppSeckillGoodsVO seckillGoodsResult : seckillGoodsResults) {
                Integer seckillId = seckillGoodsResult.getSeckillId();
                Integer commonId = seckillGoodsResult.getCommonId();
                Integer goodsId = seckillGoodsResult.getGoodsId();
                //查询该活动是否还有其他秒杀库存不为零的商品
                List<AppSeckillGoodsVO> seckillGoods = seckillGoodsMapper.selectSeckillGoods(seckillId);
                if (seckillGoods != null && seckillGoods.size()>0){
                    //只更新该商品状态
                    seckillGoodsMapper.updateSkillGoods1(goodsId);
//                    seckillGoodsMapper.updateSkillGoodsStatus(commonId);
//                    seckillGoodsMapper.updateSkillGoods(seckillId);
//                    seckillGoodsMapper.updateGoodsStatus(seckillId);
                }else{
                    seckillGoodsMapper.updateSkillGoodsStatus(commonId);
                    seckillGoodsMapper.updateSkillGoods(seckillId);
                    seckillGoodsMapper.updateGoodsStatus(seckillId);
                }
            }
        }
    }

}
